﻿using System;
using System.Configuration;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KPIS.DBM;
using KPIS.GERP.GFMS.MODEL;
using KPIS.GERP.GFMS.IDAL;

namespace KPIS.GERP.GFMS.DAL
{
    public class D_FIM_MAS_CalulateTaxs : IDAL_FIM_MAS_CalulateTaxs
    {
        DBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString);
        ConvertNullable cn = new ConvertNullable();
        //

        public M_FIM_MAS_CalulateTaxs GetInfo(int seq)
        {
            string strSQL;
            DataRowCollection drc = null;
            M_FIM_MAS_CalulateTaxs info = new M_FIM_MAS_CalulateTaxs();
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(1);

                dbManager.AddParameters(0, "@seq", seq);

                strSQL = "SELECT *"
                    + " FROM fim_mas_calulate_taxs"
                    + " WHERE cal_tax_seq = @seq";

                drc = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows;
                if (drc.Count > 0)
                {
                    info.cal_tax_seq = Convert.ToInt32(drc[0]["cal_tax_seq"]);
                    info.pay_year = cn.ConvertNullInt(drc[0]["pay_year"]);
                    info.expense_per = cn.ConvertNullDouble(drc[0]["expense_per"]);
                    info.expense_max = cn.ConvertNullDouble(drc[0]["expense_max"]);
                    info.sup_edu_per = cn.ConvertNullDouble(drc[0]["sup_edu_per"]);
                    info.sup_edu_per_max = cn.ConvertNullDouble(drc[0]["sup_edu_per_max"]);
                    info.sup_sport_per = cn.ConvertNullDouble(drc[0]["sup_sport_per"]);
                    info.sup_sport_per_max = cn.ConvertNullDouble(drc[0]["sup_sport_per_max"]);
                    info.contribute_per_max = cn.ConvertNullDouble(drc[0]["contribute_per_max"]);
                    info.reserve_1_max = cn.ConvertNullDouble(drc[0]["reserve_1_max"]);
                    info.reserve_2_max = cn.ConvertNullDouble(drc[0]["reserve_2_max"]);
                    info.reserve_2_per_max = cn.ConvertNullDouble(drc[0]["reserve_2_per_max"]);
                    info.reserve_gov_office_max = cn.ConvertNullDouble(drc[0]["reserve_gov_office_max"]);
                    info.reserve_teacher_max = cn.ConvertNullDouble(drc[0]["reserve_teacher_max"]);
                    info.over_age = cn.ConvertNullInt(drc[0]["over_age"]);
                    info.over_age_amount = cn.ConvertNullDouble(drc[0]["over_age_amount"]);
                    info.reduce = cn.ConvertNullDouble(drc[0]["reduce"]);
                    info.child_non_edu = cn.ConvertNullDouble(drc[0]["child_non_edu"]);
                    info.child_edu = cn.ConvertNullDouble(drc[0]["child_edu"]);
                    info.child_count = cn.ConvertNullInt(drc[0]["child_count"]);
                    info.parent = cn.ConvertNullDouble(drc[0]["parent"]);
                    info.parent_ins_max = cn.ConvertNullDouble(drc[0]["parent_ins_max"]);
                    info.disabled = cn.ConvertNullDouble(drc[0]["disabled"]);
                    info.ins_1_max = cn.ConvertNullDouble(drc[0]["ins_1_max"]);
                    info.ins_2_max = cn.ConvertNullDouble(drc[0]["ins_2_max"]);
                    info.rmf_per_max = cn.ConvertNullDouble(drc[0]["rmf_per_max"]);
                    info.rmf_max = cn.ConvertNullDouble(drc[0]["rmf_max"]);
                    info.ltf_per_max = cn.ConvertNullDouble(drc[0]["ltf_per_max"]);
                    info.ltf_max = cn.ConvertNullDouble(drc[0]["ltf_max"]);
                    info.loan_max = cn.ConvertNullDouble(drc[0]["loan_max"]);
                    info.tax_per1 = cn.ConvertNullDouble(drc[0]["tax_per1"]);
                    info.tax_per2 = cn.ConvertNullDouble(drc[0]["tax_per2"]);
                    info.tax_per3 = cn.ConvertNullDouble(drc[0]["tax_per3"]);
                    info.tax_per4 = cn.ConvertNullDouble(drc[0]["tax_per4"]);
                    info.tax_per5 = cn.ConvertNullDouble(drc[0]["tax_per5"]);
                    info.tax_max1 = cn.ConvertNullDouble(drc[0]["tax_max1"]);
                    info.tax_max2 = cn.ConvertNullDouble(drc[0]["tax_max2"]);
                    info.tax_max3 = cn.ConvertNullDouble(drc[0]["tax_max3"]);
                    info.tax_max4 = cn.ConvertNullDouble(drc[0]["tax_max4"]);
                    info.tax_max5 = cn.ConvertNullDouble(drc[0]["tax_max5"]);

                    info.record_status = drc[0]["record_status"].ToString();
                    info.created_by = cn.ConvertNullInt(drc[0]["created_by"]);
                    info.created_when = cn.ConvertNullDateTime(drc[0]["created_when"]);
                    info.updated_by = cn.ConvertNullInt(drc[0]["updated_by"]);
                    info.updated_when = cn.ConvertNullDateTime(drc[0]["updated_when"]);
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }

            return info;
        }

        public M_FIM_MAS_CalulateTaxs GetInfoFromYear(int pay_year)
        {
            string strSQL;
            DataRowCollection drc = null;
            M_FIM_MAS_CalulateTaxs info = new M_FIM_MAS_CalulateTaxs();
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(1);

                dbManager.AddParameters(0, "@pay_year", pay_year);

                strSQL = "SELECT *"
                    + " FROM fim_mas_calulate_taxs"
                    + " WHERE pay_year = @pay_year";

                drc = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows;
                if (drc.Count > 0)
                {
                    info.cal_tax_seq = Convert.ToInt32(drc[0]["cal_tax_seq"]);
                    info.pay_year = cn.ConvertNullInt(drc[0]["pay_year"]);
                    info.expense_per = cn.ConvertNullDouble(drc[0]["expense_per"]);
                    info.expense_max = cn.ConvertNullDouble(drc[0]["expense_max"]);
                    info.sup_edu_per = cn.ConvertNullDouble(drc[0]["sup_edu_per"]);
                    info.sup_edu_per_max = cn.ConvertNullDouble(drc[0]["sup_edu_per_max"]);
                    info.sup_sport_per = cn.ConvertNullDouble(drc[0]["sup_sport_per"]);
                    info.sup_sport_per_max = cn.ConvertNullDouble(drc[0]["sup_sport_per_max"]);
                    info.contribute_per_max = cn.ConvertNullDouble(drc[0]["contribute_per_max"]);
                    info.reserve_1_max = cn.ConvertNullDouble(drc[0]["reserve_1_max"]);
                    info.reserve_2_max = cn.ConvertNullDouble(drc[0]["reserve_2_max"]);
                    info.reserve_2_per_max = cn.ConvertNullDouble(drc[0]["reserve_2_per_max"]);
                    info.reserve_gov_office_max = cn.ConvertNullDouble(drc[0]["reserve_gov_office_max"]);
                    info.reserve_teacher_max = cn.ConvertNullDouble(drc[0]["reserve_teacher_max"]);
                    info.over_age = cn.ConvertNullInt(drc[0]["over_age"]);
                    info.over_age_amount = cn.ConvertNullDouble(drc[0]["over_age_amount"]);
                    info.reduce = cn.ConvertNullDouble(drc[0]["reduce"]);
                    info.child_non_edu = cn.ConvertNullDouble(drc[0]["child_non_edu"]);
                    info.child_edu = cn.ConvertNullDouble(drc[0]["child_edu"]);
                    info.child_count = cn.ConvertNullInt(drc[0]["child_count"]);
                    info.parent = cn.ConvertNullDouble(drc[0]["parent"]);
                    info.parent_ins_max = cn.ConvertNullDouble(drc[0]["parent_ins_max"]);
                    info.disabled = cn.ConvertNullDouble(drc[0]["disabled"]);
                    info.ins_1_max = cn.ConvertNullDouble(drc[0]["ins_1_max"]);
                    info.ins_2_max = cn.ConvertNullDouble(drc[0]["ins_2_max"]);
                    info.rmf_per_max = cn.ConvertNullDouble(drc[0]["rmf_per_max"]);
                    info.rmf_max = cn.ConvertNullDouble(drc[0]["rmf_max"]);
                    info.ltf_per_max = cn.ConvertNullDouble(drc[0]["ltf_per_max"]);
                    info.ltf_max = cn.ConvertNullDouble(drc[0]["ltf_max"]);
                    info.loan_max = cn.ConvertNullDouble(drc[0]["loan_max"]);
                    info.tax_per1 = cn.ConvertNullDouble(drc[0]["tax_per1"]);
                    info.tax_per2 = cn.ConvertNullDouble(drc[0]["tax_per2"]);
                    info.tax_per3 = cn.ConvertNullDouble(drc[0]["tax_per3"]);
                    info.tax_per4 = cn.ConvertNullDouble(drc[0]["tax_per4"]);
                    info.tax_per5 = cn.ConvertNullDouble(drc[0]["tax_per5"]);
                    info.tax_max1 = cn.ConvertNullDouble(drc[0]["tax_max1"]);
                    info.tax_max2 = cn.ConvertNullDouble(drc[0]["tax_max2"]);
                    info.tax_max3 = cn.ConvertNullDouble(drc[0]["tax_max3"]);
                    info.tax_max4 = cn.ConvertNullDouble(drc[0]["tax_max4"]);
                    info.tax_max5 = cn.ConvertNullDouble(drc[0]["tax_max5"]);

                    info.record_status = drc[0]["record_status"].ToString();
                    info.created_by = cn.ConvertNullInt(drc[0]["created_by"]);
                    info.created_when = cn.ConvertNullDateTime(drc[0]["created_when"]);
                    info.updated_by = cn.ConvertNullInt(drc[0]["updated_by"]);
                    info.updated_when = cn.ConvertNullDateTime(drc[0]["updated_when"]);
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }

            return info;
        }

        public void Insert(M_FIM_MAS_CalulateTaxs info)
        {
            string strSQL;
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(43);

                dbManager.AddParameters(0, "@cal_tax_seq", info.cal_tax_seq);
                dbManager.AddParameters(1, "@pay_year", info.pay_year);
                dbManager.AddParameters(2, "@expense_per", info.expense_per);
                dbManager.AddParameters(3, "@expense_max", info.expense_max);
                dbManager.AddParameters(4, "@sup_edu_per", info.sup_edu_per);
                dbManager.AddParameters(5, "@sup_edu_per_max", info.sup_edu_per_max);
                dbManager.AddParameters(6, "@sup_sport_per", info.sup_sport_per);
                dbManager.AddParameters(7, "@sup_sport_per_max", info.sup_sport_per_max);
                dbManager.AddParameters(8, "@contribute_per_max", info.contribute_per_max);
                dbManager.AddParameters(9, "@reserve_1_max", info.reserve_1_max);
                dbManager.AddParameters(10, "@reserve_2_max", info.reserve_2_max);
                dbManager.AddParameters(11, "@reserve_2_per_max", info.reserve_2_per_max);
                dbManager.AddParameters(12, "@reserve_gov_office_max", info.reserve_gov_office_max);
                dbManager.AddParameters(13, "@reserve_teacher_max", info.reserve_teacher_max);
                dbManager.AddParameters(14, "@over_age", info.over_age);
                dbManager.AddParameters(15, "@over_age_amount", info.over_age_amount);
                dbManager.AddParameters(16, "@reduce", info.reduce);
                dbManager.AddParameters(17, "@child_non_edu", info.child_non_edu);
                dbManager.AddParameters(18, "@child_edu", info.child_edu);
                dbManager.AddParameters(19, "@child_count", info.child_count);
                dbManager.AddParameters(20, "@parent", info.parent);
                dbManager.AddParameters(21, "@parent_ins_max", info.parent_ins_max);
                dbManager.AddParameters(22, "@disabled", info.disabled);
                dbManager.AddParameters(23, "@ins_1_max", info.ins_1_max);
                dbManager.AddParameters(24, "@ins_2_max", info.ins_2_max);
                dbManager.AddParameters(25, "@rmf_per_max", info.rmf_per_max);
                dbManager.AddParameters(26, "@rmf_max", info.rmf_max);
                dbManager.AddParameters(27, "@ltf_per_max", info.ltf_per_max);
                dbManager.AddParameters(28, "@ltf_max", info.ltf_max);
                dbManager.AddParameters(29, "@loan_max", info.loan_max);
                dbManager.AddParameters(30, "@tax_per1", info.tax_per1);
                dbManager.AddParameters(31, "@tax_per2", info.tax_per2);
                dbManager.AddParameters(32, "@tax_per3", info.tax_per3);
                dbManager.AddParameters(33, "@tax_per4", info.tax_per4);
                dbManager.AddParameters(34, "@tax_per5", info.tax_per5);
                dbManager.AddParameters(35, "@tax_max1", info.tax_max1);
                dbManager.AddParameters(36, "@tax_max2", info.tax_max2);
                dbManager.AddParameters(37, "@tax_max3", info.tax_max3);
                dbManager.AddParameters(38, "@tax_max4", info.tax_max4);
                dbManager.AddParameters(39, "@tax_max5", info.tax_max5);

                dbManager.AddParameters(40, "@record_status", SystemInfo._ActiveRecordStatus);
                dbManager.AddParameters(41, "@created_by", info.created_by);
                dbManager.AddParameters(42, "@created_when", info.created_when);

                strSQL = "INSERT INTO fim_mas_calulate_taxs"
                    + "(pay_year, expense_per, expense_max, sup_edu_per, sup_edu_per_max"
                        + ", sup_sport_per, sup_sport_per_max, contribute_per_max"
                        + ", reserve_1_max, reserve_2_max, reserve_2_per_max, reserve_gov_office_max"
                        + ", reserve_teacher_max, over_age, over_age_amount, reduce"
                        + ", child_non_edu, child_edu, child_count, parent, parent_ins_max"
                        + ", disabled, ins_1_max, ins_2_max, rmf_per_max, rmf_max"
                        + ", ltf_per_max, ltf_max, loan_max"
                        + ", tax_per1, tax_per2, tax_per3, tax_per4, tax_per5"
                        + ", tax_max1, tax_max2, tax_max3, tax_max4, tax_max5"
                        + ", record_status, created_by, created_when)"
                    + " VALUES (@pay_year"
                        + ", @expense_per"
                        + ", @expense_max"
                        + ", @sup_edu_per"
                        + ", @sup_edu_per_max"
                        + ", @sup_sport_per"
                        + ", @sup_sport_per_max"
                        + ", @contribute_per_max"
                        + ", @reserve_1_max"
                        + ", @reserve_2_max"
                        + ", @reserve_2_per_max"
                        + ", @reserve_gov_office_max"
                        + ", @reserve_teacher_max"
                        + ", @over_age"
                        + ", @over_age_amount"
                        + ", @reduce"
                        + ", @child_non_edu"
                        + ", @child_edu"
                        + ", @child_count"
                        + ", @parent"
                        + ", @parent_ins_max"
                        + ", @disabled"
                        + ", @ins_1_max"
                        + ", @ins_2_max"
                        + ", @rmf_per_max"
                        + ", @rmf_max"
                        + ", @ltf_per_max"
                        + ", @ltf_max"
                        + ", @loan_max"
                        + ", @tax_per1"
                        + ", @tax_per2"
                        + ", @tax_per3"
                        + ", @tax_per4"
                        + ", @tax_per5"
                        + ", @tax_max1"
                        + ", @tax_max2"
                        + ", @tax_max3"
                        + ", @tax_max4"
                        + ", @tax_max5"

                        + ", @record_status"
                        + ", @created_by"
                        + ", @created_when"
                        + ")";

                dbManager.ExecuteNonQuery(CommandType.Text, strSQL);
            }
            catch
            {
                throw;
            }
            finally
            {
                dbManager.Dispose();
            }
        }

        public void Update(M_FIM_MAS_CalulateTaxs info)
        {
            string strSQL;
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(42);

                dbManager.AddParameters(0, "@cal_tax_seq", info.cal_tax_seq);
                dbManager.AddParameters(1, "@pay_year", info.pay_year);
                dbManager.AddParameters(2, "@expense_per", info.expense_per);
                dbManager.AddParameters(3, "@expense_max", info.expense_max);
                dbManager.AddParameters(4, "@sup_edu_per", info.sup_edu_per);
                dbManager.AddParameters(5, "@sup_edu_per_max", info.sup_edu_per_max);
                dbManager.AddParameters(6, "@sup_sport_per", info.sup_sport_per);
                dbManager.AddParameters(7, "@sup_sport_per_max", info.sup_sport_per_max);
                dbManager.AddParameters(8, "@contribute_per_max", info.contribute_per_max);
                dbManager.AddParameters(9, "@reserve_1_max", info.reserve_1_max);
                dbManager.AddParameters(10, "@reserve_2_max", info.reserve_2_max);
                dbManager.AddParameters(11, "@reserve_2_per_max", info.reserve_2_per_max);
                dbManager.AddParameters(12, "@reserve_gov_office_max", info.reserve_gov_office_max);
                dbManager.AddParameters(13, "@reserve_teacher_max", info.reserve_teacher_max);
                dbManager.AddParameters(14, "@over_age", info.over_age);
                dbManager.AddParameters(15, "@over_age_amount", info.over_age_amount);
                dbManager.AddParameters(16, "@reduce", info.reduce);
                dbManager.AddParameters(17, "@child_non_edu", info.child_non_edu);
                dbManager.AddParameters(18, "@child_edu", info.child_edu);
                dbManager.AddParameters(19, "@child_count", info.child_count);
                dbManager.AddParameters(20, "@parent", info.parent);
                dbManager.AddParameters(21, "@parent_ins_max", info.parent_ins_max);
                dbManager.AddParameters(22, "@disabled", info.disabled);
                dbManager.AddParameters(23, "@ins_1_max", info.ins_1_max);
                dbManager.AddParameters(24, "@ins_2_max", info.ins_2_max);
                dbManager.AddParameters(25, "@rmf_per_max", info.rmf_per_max);
                dbManager.AddParameters(26, "@rmf_max", info.rmf_max);
                dbManager.AddParameters(27, "@ltf_per_max", info.ltf_per_max);
                dbManager.AddParameters(28, "@ltf_max", info.ltf_max);
                dbManager.AddParameters(29, "@loan_max", info.loan_max);
                dbManager.AddParameters(30, "@tax_per1", info.tax_per1);
                dbManager.AddParameters(31, "@tax_per2", info.tax_per2);
                dbManager.AddParameters(32, "@tax_per3", info.tax_per3);
                dbManager.AddParameters(33, "@tax_per4", info.tax_per4);
                dbManager.AddParameters(34, "@tax_per5", info.tax_per5);
                dbManager.AddParameters(35, "@tax_max1", info.tax_max1);
                dbManager.AddParameters(36, "@tax_max2", info.tax_max2);
                dbManager.AddParameters(37, "@tax_max3", info.tax_max3);
                dbManager.AddParameters(38, "@tax_max4", info.tax_max4);
                dbManager.AddParameters(39, "@tax_max5", info.tax_max5);

                dbManager.AddParameters(40, "@updated_by", info.updated_by);
                dbManager.AddParameters(41, "@updated_when", info.updated_when);

                strSQL = "UPDATE fim_mas_calulate_taxs"
                    + " SET pay_year = @pay_year"
                        + ", expense_per = @expense_per"
                        + ", expense_max = @expense_max"
                        + ", sup_edu_per = @sup_edu_per"
                        + ", sup_edu_per_max = @sup_edu_per_max"
                        + ", sup_sport_per = @sup_sport_per"
                        + ", sup_sport_per_max = @sup_sport_per_max"
                        + ", contribute_per_max = @contribute_per_max"
                        + ", reserve_1_max = @reserve_1_max"
                        + ", reserve_2_max = @reserve_2_max"
                        + ", reserve_2_per_max = @reserve_2_per_max"
                        + ", reserve_gov_office_max = @reserve_gov_office_max"
                        + ", reserve_teacher_max = @reserve_teacher_max"
                        + ", over_age = @over_age"
                        + ", over_age_amount = @over_age_amount"
                        + ", reduce = @reduce"
                        + ", child_non_edu = @child_non_edu"
                        + ", child_edu = @child_edu"
                        + ", child_count = @child_count"
                        + ", parent = @parent"
                        + ", parent_ins_max = @parent_ins_max"
                        + ", disabled = @disabled"
                        + ", ins_1_max = @ins_1_max"
                        + ", ins_2_max = @ins_2_max"
                        + ", rmf_per_max = @rmf_per_max"
                        + ", rmf_max = @rmf_max"
                        + ", ltf_per_max = @ltf_per_max"
                        + ", ltf_max = @ltf_max"
                        + ", loan_max = @loan_max"
                        + ", tax_per1 = @tax_per1"
                        + ", tax_per2 = @tax_per2"
                        + ", tax_per3 = @tax_per3"
                        + ", tax_per4 = @tax_per4"
                        + ", tax_per5 = @tax_per5"
                        + ", tax_max1 = @tax_max1"
                        + ", tax_max2 = @tax_max2"
                        + ", tax_max3 = @tax_max3"
                        + ", tax_max4 = @tax_max4"
                        + ", tax_max5 = @tax_max5"

                        + ", updated_by = @updated_by"
                        + ", updated_when = @updated_when"
                    + " WHERE cal_tax_seq = @cal_tax_seq";

                dbManager.ExecuteNonQuery(CommandType.Text, strSQL);
            }
            catch
            {
                throw;
            }
            finally
            {
                dbManager.Dispose();
            }
        }
    }
}
